// 1. 基础
// 申明
function getSum1(a: number): number {
  return a;
}
// 表达式
type FnType = (a: number) => number;
let getSum2: FnType = function (a: number): number {
  return a;
};

interface FnType2 {
  (a: number): number;
  // (b: number): string;
}
let getSum3: FnType2 = function (a: number): number {
  return 1;
};

// 剩余参数
function getSum4(a: number[], ...items: any[]): number {
  console.log(items);
  return 1;
}
getSum4([1, 2, 34], 3, 4, 5, 6, 6);

// 重载 （最精确的在最前面）
function reverse(x: number): number;
function reverse(x: string): string;
function reverse(x: number | string): number | string | void {
  if (typeof x === "number") {
    return Number(x.toString().split("").reverse().join(""));
  } else if (typeof x === "string") {
    return x.split("").reverse().join("");
  }
}
